/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package interceptors;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

/**
 *
 * @author suria
 */
public class LoggerInterceptor implements Interceptor {

    public LoggerInterceptor() {
    }

    public void destroy() {
        // Not Used
    }

    public void init() {
        // Not Used
    }

    public String intercept(ActionInvocation actionInvocation) throws Exception {
        String className =
                actionInvocation.getAction().getClass().getName();
        long startTime = System.currentTimeMillis();
        System.out.println("Before calling action: " + className);

        String result = actionInvocation.invoke();

        long endTime = System.currentTimeMillis();
        System.out.println("After calling action: " + className
                + " Time taken: " + (endTime - startTime)
                + " ms");

        return result;

    }
}
